# class Solution:
#     def reverse(self, x: int) -> int:
#         flag=0
#         if x == 0:
#             return 0
#         if x<0:
#             flag=1
#             x=-x
#         a=0
#         while(x):
#             a=a*10+x%10
#             x=x//10
#         if a>2**31-1 or a<-2**31:
#             return 0
#         if flag==1:
#             a=-a
#         return a


class Solution:
    def reverse(self, x: int) -> int:
        flag=0
        if x == 0:
            return 0
        if x<0:
            flag=1
            x=-x
        s1=str(x)
        s2=s1[::-1]
        n1=int(s2)
        if flag==1:
            n1=-n1
        if n1<-2**31:
            return 0
        if n1>2**31-1:
            return 0
        return n1


x=Solution()
print(x.reverse(-12323213))
